// 2025/11/21
// 最大子数组和

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int prev = 0, ans = nums[0];
        for(auto& num : nums)
        {
            prev = max(num, prev + num);
            ans = max(ans, prev);
        }
        return ans;
    }
};